﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PM.Entity;
using System.Data;
using System.Data.OracleClient;

namespace PM.Services
{
    public static class BankAccTypeServices
    {
        private static BankAccType GetBankAccTypeFromDataReader(IDataReader dataReader)
        {
            BankAccType retVal = null;
            if (dataReader != null && !dataReader.IsClosed)
            {
                retVal = new BankAccType();
                retVal.TypeCode = dataReader["TYPE_CODE"].ToString();
                retVal.Name = dataReader["TYPE_NAME"].ToString();                
            }
            return retVal;
        }

        public static BankAccTypesCollection GetAllBankAccTypesCollection()
        {
            BankAccTypesCollection retVal = null;
            OracleConnection con = new OracleConnection();

            try
            {
                con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                con.Open();
                OracleCommand cmd = new OracleCommand();
                cmd.CommandText = "select * from ACCOUNT_TYPE";
                cmd.Connection = con;

                using (IDataReader dataReader = cmd.ExecuteReader())
                {
                    retVal = new BankAccTypesCollection();
                    while (dataReader.Read())
                    {
                        BankAccType item = GetBankAccTypeFromDataReader(dataReader);
                        if (item != null)
                            retVal.Add(item);
                    }
                }
            }
            catch (System.Exception exc)
            {
                throw;
            }
            finally
            {
                con.Close();
            }
            return retVal;
        }

    }
}
